package com.cx.common;

import com.cx.common.aspect.CurrentLimitingAspect;
import com.cx.common.aspect.DistributedLockAspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author cx
 * @description: 自动配置启动类
 * @date 2023/6/2 17:09
 */
@Configuration
public class CommonAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(RedisTemplate.class)
    public DistributedLockAspect enableDistributedLocksAspect(RedisTemplate<String, String> redisTemplate) {
        return new DistributedLockAspect(redisTemplate);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(RedisTemplate.class)
    public CurrentLimitingAspect enableCurrentLimitingAspect(RedisTemplate<String, String> redisTemplate) {
        return new CurrentLimitingAspect(redisTemplate);
    }
}
